package com.sgd.generator;

import com.sgd.model.MainTemplateConfig;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

/**
 * <p>Title: </p>
 * <p>Description: 动静态模板代码生成</p>
 *
 * 将 acm-template 整个项目复制到指定的位置，并修改项目中文件的指定内容
 * @author su.gd
 * @date 2023-11-12
 */
public class MainGenerator {

    public static void main(String[] args) throws TemplateException, IOException {
        MainTemplateConfig model = new MainTemplateConfig();
        model.setLoop(false);
        model.setAuthor("555");
        model.setOutputText("666");

        doGenerator(model);
    }

    public static void doGenerator(Object model) throws TemplateException, IOException {
        // 根项目路径
        String projectPath = System.getProperty("user.dir");
        String parentPath = new File(projectPath).getParentFile().getAbsolutePath();
        /**
         * 静态文件复制
         */
        // 待复制的文件的路径
        String inputPath = parentPath + File.separator + "code-generator-demo-projects/acm-template";
        // 复制到哪里
        String outputPath = parentPath;
        StaticGenerator.copyFilesByHutool(inputPath, outputPath);

        /**
         * 动态文件复制
         */
        // 动态文件模板路径
        String inputDynamicFilePath = parentPath + File.separator + "code-generator-basic/src/main/resources/templates/MainTemplate.java.ftl";
        // 待替换的文件的路径
        String outputDynamicFilePath = outputPath + File.separator + "acm-template/src/com/yupi/acm/MainTemplate.java";
        DynamicGenerator.doGenerate(inputDynamicFilePath, outputDynamicFilePath, model);
    }
}
